#ifndef __SIGNAL_H__
#define __SIGNAL_H__
#include "common.h"
#include "logger.h"
#include "exception.h"
#include "errcode_define.h"
#include <iostream>
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
#include <string.h>


const char * sig_name[]={
	"",
	"SIGHUP",
	"SIGINT",
	"SIGQUIT",
	"SIGILL",
	"SIGTRAP",
	"SIGABRT",
	"SIGIOT",
	"SIGBUS",
	"SIGFPE",
	"SIGKILL",
	"SIGUSR1",
	"SIGSEGV",
	"SIGUSR2",
	"SIGPIPE",
	"SIGALRM",
	"SIGTERM",
	"SIGSTKFLT",
	"SIGCHLD",
	"SIGCONT",
	"SIGSTOP",
	"SIGTSTP",
	"SIGTTIN",
	"SIGTTOU",
	"SIGURG",
	"SIGXCPU",
	"SIGXFSZ",
	"SIGVTALRM",
	"SIGPROF",
	"SIGWINCH",
	"SIGIO or SIGPOLL",
	"SIGPWR",
	"SIGSYS",
	"SIGUNUSED"
};

inline const char * signame( int sig ){
	const char * pname = "";
	if( sig <= 32 ){
		pname = sig_name[sig];
	}
	return pname;
}

inline void SendSignal(pid_t pid, int sig){
	std::ostringstream oss;
	
	oss << "Send signal:" << strsignal(sig) << " signum:" << sig << " Desc:\"" << strsignal(sig) <<"\" To Pid:" << pid ;
	LOG(INFO) << oss.str() << std::endl;
	int ret = kill(pid, sig);
	if( 0 != ret ){
		THROWLOG( FATAL, "", EXCP_SEND_SIGNAL_FAILED , oss.str());
	}
	return;
}
#endif
